package com.example.hand.springbootweb.api.controller;


import com.example.hand.springbootweb.app.service.LoginService;
import com.example.hand.springbootweb.domain.entity.LoginJPA;
import com.example.hand.springbootweb.domain.vo.LoginVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;


@Controller
public class LoginController {

    @Autowired
    LoginService loginService;

    @RequestMapping({"/","/index"})
    public String test2(){
        return "login";
    }
    @RequestMapping("/123")
    public String test123(){
        return "login";
    }



    @RequestMapping("/login1")
    public ModelAndView Login( LoginVo loginVo){

        LoginJPA loginJPA=new LoginJPA();
        ModelAndView modelAndView=new ModelAndView();

        loginJPA=loginService.loginJPAUser(loginVo);

        if (loginJPA.getPassword()!=null && loginJPA.getUserName()!=null){


            modelAndView.addObject("username",loginJPA.getUserName());
            modelAndView.setViewName("loginOk");
            return modelAndView;
        }else {
            modelAndView.setViewName("login");
            return modelAndView;
        }

    }

    @RequestMapping("/1234")
    @ResponseBody
    public String test1234(){
        return "login";
    }

}
